package com.woniuxy.main.chat_yj.controller;

import com.woniuxy.main.chat_yj.model.ChatRecord;
import com.woniuxy.main.chat_yj.model.User;
import com.woniuxy.main.chat_yj.service.UserService_Yj;
import com.woniuxy.main.mycenter_ty.pojo.User_Ty;
import com.woniuxy.main.mycenter_ty.service.MyCenterService;
import com.woniuxy.main.utils.ResponseResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 聊天controller
 * author：
 */
@RestController
@RequestMapping("/user")
public class ChatController {

    @Autowired
    private UserService_Yj userService;
	@Autowired
	private MyCenterService personCenterservice;
   
	
    /**
     * 获取用户列表  
     * @param user
     * @return
     */
    @RequestMapping("/getUserList")
    public ResponseResult getUserList(@RequestBody(required = false) User user){    	
       	String phone = (String)SecurityUtils.getSubject().getPrincipal();  // 获取当前登录用户
    	User_Ty us = personCenterservice.queryAllInfoByPhone(phone);   // 根据手机号查询个人信息
    	Integer uid = us.getUser_id();  
    	List<User> list = userService.getUserList(uid);
        return ResponseResult.ok(list);
    }

    
    /**
     * 聊天记录
     * @param username
     * @return
     */
    @RequestMapping("/chatrecord")    
    @ResponseBody
    public List<ChatRecord> getChatRecord(String username){
    	String phone = (String)SecurityUtils.getSubject().getPrincipal();  // 获取当前登录用户
    	User_Ty us = personCenterservice.queryAllInfoByPhone(phone);   // 根据手机号查询个人信息
    	String  name = us.getUser_nickname();  
    	ChatRecord cr = new ChatRecord();
    	cr.setSend_user(name);    // 本人
    	cr.setReceive_user(username);  // 好友  	
    	List<ChatRecord> list = userService.query(cr);    //聊天记录
    	return list;    	
    }
    
        
}
